package com.framework.main.sys.dept.action;

import java.util.List;

import com.framework.base.struts.BaseAction;
import com.framework.base.struts.Result;
import com.framework.base.util.Struts2Utils;
import com.framework.main.sys.dept.domain.DeptVO;
import com.framework.main.sys.dept.service.DeptService;
import com.framework.main.sys.role.service.RoleService;
import com.framework.main.sys.user.domain.UserVo;

/**
 * Title:部门 Action
 * Description:用于管理部门数据请求
 * tabaleName(对应的表名):SYS_DEPT
 * Copyright: Copyright (c) 年份
 * Company: www.51wuxia.com
 * @author：www.51wuxia.com
 * @version 1.0
 */
@SuppressWarnings("serial")
public class DeptAction extends BaseAction{
	private DeptService deptService;
	private RoleService roleService;
	public RoleService getRoleService() {
		return roleService;
	}
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	public DeptService getDeptService() {
		return deptService;
	}
	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	
	public DeptAction() {
		getLogger().info("deptaction init");
	}
	
	/**
	 * 用于删除指定的数据
	 * 
	 * @return
	 * @throws Exception
	 */
	/*public String doDelete() throws Exception {
		String[] pks=Struts2Utils.getRequest().getParameterValues("fid");
		String resultName =this.getDeptService().doDelete(pks);
		return resultName;
	}*/
	
	
	/**
	 * 显示组织显示树
	 * @param cfg
	 */
	public String toListsj() throws Exception {
		List<DeptVO> depts=this.deptService.toListsj();
		Struts2Utils.getRequest().setAttribute("depts", depts);
		List<?> roles=this.getRoleService().toListRole();
		Struts2Utils.getRequest().setAttribute("roles", roles);
		Result result=this.getDeptService().toList(Struts2Utils.getParameterMap(getQueryMap(),this.getVo()));
		return result.getForwardName();
	}
	
	/**
	 * 根据上级组织显示数据
	 * @param cfg
	 */
	/*public String toList()throws Exception{
		Result result=this.getDeptService().toList(Struts2Utils.getParameterMap(getQueryMap(),this.getVo()));
		Struts2Utils.getRequest().setAttribute("pagination", result.getPage());
		return result.getForwardName();
	}*/
	
	/**
	 * 显示人员选择数据
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String toselectUser()throws Exception{
		String pk = Struts2Utils.getRequest().getParameter("fid");
		if(pk==null||"".equals(pk)){
			pk=(String)Struts2Utils.getRequest().getAttribute("pk");
		}
		List<UserVo> userRole=this.deptService.toselectUser("toUserDept", pk);
		List<UserVo> userKxRole=this.deptService.toselectUser("toKxUserDept", pk);
		Result result=this.getDeptService().toList(Struts2Utils.getParameterMap(getQueryMap(),this.getVo()));
		Struts2Utils.getRequest().setAttribute("userRole", userRole);
		Struts2Utils.getRequest().setAttribute("userKxRole", userKxRole);
		Struts2Utils.getRequest().setAttribute("pk", pk);
		return result.getForwardName();
	}
	
	/**
	 * 显示人员选择数据
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String ByIdLoadUsers()throws Exception{
		String pk = Struts2Utils.getRequest().getParameter("fid");
		if(pk==null||"".equals(pk)){
			pk=(String)Struts2Utils.getRequest().getAttribute("pk");
		}
		List<UserVo> userRole=this.deptService.toselectUser("toUserDept", pk);
		Struts2Utils.getRequest().setAttribute("users", userRole);
		Struts2Utils.getRequest().setAttribute("pk", pk);
		return SUCCESS;
	}
	
	/**
	 * 选择人员
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String doInsertUR() throws Exception {
		String userid = Struts2Utils.getRequest().getParameter("users");
		String pk = Struts2Utils.getRequest().getParameter("pk");
		this.getDeptService().doInsertUR(pk, userid);
		Struts2Utils.getRequest().setAttribute("pk",pk);
		return this.toselectUser();
	}
	
	public String doInsertAndTask() throws Exception {
		this.getVo().setCreateidf(Struts2Utils.getCurrentUser().getIdf());
		this.getVo().setDeptidf(Struts2Utils.getCurrentUserDeptId());
		String resultName = ((DeptService)this.getBaseService()).doInsert(this.getVo());
		return resultName;
	}
	
	/**
	 * 进入部门管理界面
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String toDeptManage()throws Exception{
		return SUCCESS;
	}
	/**
	 * 进入班级管理界面
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String toMenu() throws Exception {
		return SUCCESS;
	}
	/**
	 * 进入部门管理界面
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String toDeptMenu()throws Exception{
		return SUCCESS;
	}
	
	/**
	 * 进入部门管理界面
	 * @param cfg
	 * @return
	 * @throws Exception
	 */
	public String toDeptSpace()throws Exception{
		return SUCCESS;
	}
}

